import '../helper/dioHelper2.dart';

class HourData {
  int ID;
  String TM;
  double H1;
  double H2;
  double FH1;
  double FH2;
  double FH3;
  double FH4;
  double FDLL1;
  double FDLL2;
  double FDLL3;
  double FDLL4;
  double CSDKD;
  double CSDLL;
  double XHDKD1;
  double XHDLL1;
  double XHDKD2;
  double XHDLL2;
  double YHDKD;
  double YHDLL;
  double H3;
  double QF;
  double WF;
  double E;
  double C;
  double A;
  double V;
  double QP;
  double QZ;
  double R;
  double LastH;
  bool IfOK;

  HourData(
      this.ID,
      this.TM,
      this.H1,
      this.H2,
      this.FH1,
      this.FH2,
      this.FH3,
      this.FH4,
      this.FDLL1,
      this.FDLL2,
      this.FDLL3,
      this.FDLL4,
      this.CSDKD,
      this.CSDLL,
      this.XHDKD1,
      this.XHDLL1,
      this.XHDKD2,
      this.XHDLL2,
      this.YHDKD,
      this.YHDLL,
      this.H3,
      this.QF,
      this.WF,
      this.E,
      this.C,
      this.A,
      this.V,
      this.QP,
      this.QZ,
      this.R,
      this.LastH,
      this.IfOK);
  HourData.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        TM = json["TM"],
        H1 = json["H1"] * 1.0,
        H2 = json["H2"] * 1.0,
        FH1 = json["FH1"] * 1.0,
        FH2 = json["FH2"] * 1.0,
        FH3 = json["FH3"] * 1.0,
        FH4 = json["FH4"] * 1.0,
        FDLL1 = json["FDLL1"] * 1.0,
        FDLL2 = json["FDLL2"] * 1.0,
        FDLL3 = json["FDLL3"] * 1.0,
        FDLL4 = json["FDLL4"] * 1.0,
        CSDKD = json["CSDKD"] * 1.0,
        CSDLL = json["CSDLL"] * 1.0,
        XHDKD1 = json["XHDKD1"] * 1.0,
        XHDLL1 = json["XHDLL1"] * 1.0,
        XHDKD2 = json["XHDKD2"] * 1.0,
        XHDLL2 = json["XHDLL2"] * 1.0,
        YHDKD = json["YHDKD"] * 1.0,
        YHDLL = json["YHDLL"] * 1.0,
        H3 = json["H3"] * 1.0,
        QF = json["QF"] * 1.0,
        WF = json["WF"] * 1.0,
        E = json["E"] * 1.0,
        C = json["C"] * 1.0,
        A = json["A"] * 1.0,
        V = json["V"] * 1.0,
        QP = json["QP"] * 1.0,
        QZ = json["QZ"] * 1.0,
        R = json["R"] * 1.0,
        LastH = json["LastH"] * 1.0,
        IfOK = json["IfOK"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'TM': TM,
        'H1': H1,
        'H2': H2,
        'FH1': FH1,
        'FH2': FH2,
        'FH3': FH3,
        'FH4': FH4,
        'FDLL1': FDLL1,
        'FDLL2': FDLL2,
        'FDLL3': FDLL3,
        'FDLL4': FDLL4,
        'CSDKD': CSDKD,
        'CSDLL': CSDLL,
        'XHDKD1': XHDKD1,
        'XHDLL1': XHDLL1,
        'XHDKD2': XHDKD2,
        'XHDLL2': XHDLL2,
        'YHDKD': YHDKD,
        'YHDLL': YHDLL,
        'H3': H3,
        'QF': QF,
        'WF': WF,
        'E': E,
        'C': C,
        'A': A,
        'V': V,
        'QP': QP,
        'QZ': QZ,
        'R': R,
        'LastH': LastH,
        'IfOK': IfOK,
      };
  static Future<bool> Add(HourData x1) async {
    var response = await DioHelper.Post("/HourData/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(HourData x1) async {
    var response = await DioHelper.Post("/HourData/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(HourData x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/HourData/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<HourData?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/HourData/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new HourData.fromJson(response.data);
    return null;
  }

  static Future<List<HourData>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/HourData/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <HourData>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new HourData.fromJson(x));
      }
    }
    return list1;
  }


  static List<HourData> GetListByValue(dynamic value)  {
    print(value);
    var list1 = <HourData>[];
    
      for (var x in value) {
        list1.add(new HourData.fromJson(x));
      }
    print(list1);
    return list1;
  }


  static Future<List<HourData>> GetAllList() async {
    var response = await DioHelper.Get("/HourData/GetAllList", {});
    var list1 = <HourData>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new HourData.fromJson(x));
      }
    }
    return list1;
  }
}
